#include "StdAfx.h"
#include "MemberSql.h"

CMemberSql::CMemberSql()
{

}

CMemberSql::~CMemberSql(void)
{
	
}
BOOL CMemberSql::ConnectDB(MYSQLSERVERINFO *mysqlserverinfo)
{
	return m_DBAssist.ConnectDB(mysqlserverinfo);
}
BOOL CMemberSql::CloseDB()
{
	return m_DBAssist.CloseDB();
}
void CMemberSql::InsertMember(Member* mem)
{
	CString str=L"Insert into memberinfo values ('"+(mem->id)+L"','"+(mem->password)+L"')";
	m_DBAssist.Execute(str);
}
void CMemberSql::DeleteMember(Member* mem)
{
	CString str=L"delete from memberinfo where id='"+(mem->id)+L"'and password='"+(mem->password)+L"'";
	m_DBAssist.Execute(str);
}
std::vector<Member>* CMemberSql::GetMembers()
{
	return m_DBAssist.Query(L"select * from memberinfo");
}

BOOL CMemberSql::IsExist(Member* mem)
{
	CString str =L"select * from memberinfo where id='"+(mem->id)+L"'";
	std::vector<Member> *pvector = m_DBAssist.Query(str);
	if (pvector->empty())
	{		
		delete pvector;
		return FALSE;
	}
	delete pvector;
	return TRUE;
}

BOOL CMemberSql::IsValid(Member* mem)
{
	CString str =L"select * from memberinfo where id='"+(mem->id)+L"'and password='"+(mem->password)+L"'";
	std::vector<Member> *pvector = m_DBAssist.Query(str);
	if (pvector->empty())
	{		
		delete pvector;
		return FALSE;
	}
	delete pvector;
	return TRUE;
}